package com.gobo.jinghuimall.cart.entiry.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {

    private List<CartItem> items; // 商品信息

    private Integer totalCount; // 总共数量

    private Integer countType; // 商品类型的数量

    private BigDecimal totalAccount; // 总价

    private BigDecimal reducePrice = new BigDecimal(0); // 优惠价

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getTotalCount() {
        int count = 0;
        if (this.items != null && items.size() > 0) {
            for (CartItem item : this.items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if (this.items != null && items.size() > 0) {
            for (CartItem item : this.items) {
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getTotalAccount() {
        BigDecimal account = new BigDecimal(0);
        if (this.items != null && this.items.size() > 0) {
            // 1.计算总价
            for (CartItem item : this.items) {
                if (item.getChecked()) {
                    BigDecimal totalPrice = item.getTotalPrice();
                    account = account.add(totalPrice);
                }
            }
            // 2.减去优惠价格
            account = account.subtract(getReducePrice());
        }
        return account;
    }

    public BigDecimal getReducePrice() {
        return reducePrice;
    }

    public void setReducePrice(BigDecimal reducePrice) {
        this.reducePrice = reducePrice;
    }
}
